package cn.com.gzheroli.rabbitmq.service.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by lhx on 2016/9/5 9:56
 *
 * @Description
 */
@Service("fanoutProducerService")
public class FanoutProducerService {

    private Logger logger = LoggerFactory.getLogger(FanoutProducerService.class);

    @Resource
    private RabbitTemplate fanoutTemplate;

    public void sendMessage(Object message){
        logger.info("to send message:{}",message);
        //fanoutTemplate.convertAndSend(message);
        /*fanoutTemplate.convertAndSend(message, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("jobName", "hhhhhhhh");
                return message;
            }
        });*/
        String exchange=fanoutTemplate.getExchange();
        String routingKey="ccs.queue.fanout1";
        fanoutTemplate.convertAndSend(exchange,routingKey, message);
    }
}
